﻿
Imports ManagedDLL
Imports System.IO



Module ManagedPassFiltUtil

    Sub Main()

        Dim PolicyListDictionary As New Concurrent.ConcurrentDictionary(Of String, Dictionary(Of String, String))
        'Dim PolicyCoverageDictionary As Concurrent.ConcurrentDictionary(Of String, DictionaryEntry)
        'Dim PolicyElements As Concurrent.ConcurrentDictionary(Of String, DictionaryEntry)


        Dim repository As String = "\\127.0.0.1\sysvol\forest2.com\PassFilt\_Rep"

        For Each File As FileInfo In New DirectoryInfo(repository).GetFiles
            If UCase(Trim(File.Extension)) = ".MPF" Then
                Dim Policy As New Dictionary(Of String, String)
                Dim filename As String = LCase(Trim(File.Name)).ToString()
                Policy.Add("FileName", filename)
                Policy.Add("Modified", File.LastAccessTimeUtc.ToString())
                Policy.Add("Size", File.Length.ToString())
                Policy.Add("Created", File.CreationTimeUtc.ToString())
                Policy.Add("FilePath", File.FullName.ToString())
                Policy.Add("DirectoryPath", File.DirectoryName.ToString())
                Dim tryAdd As Boolean = PolicyListDictionary.TryAdd(filename, Policy)
                If tryAdd = False Then PolicyListDictionary.Item(filename) = Policy
            End If






        Next

        'Dim test As New ManagedClass
        'ICpassfilt()
        'Dim ret As Boolean = test.ManagedPasswordFilter("bubba", "bubba", "3171981-nathan", True)


    End Sub







    Public Class INIUtil

        ' API functions
        Private Declare Ansi Function GetPrivateProfileString _
          Lib "kernel32.dll" Alias "GetPrivateProfileStringA" _
          (ByVal lpApplicationName As String, _
          ByVal lpKeyName As String, ByVal lpDefault As String, _
          ByVal lpReturnedString As System.Text.StringBuilder, _
          ByVal nSize As Integer, ByVal lpFileName As String) _
          As Integer
        Private Declare Ansi Function WritePrivateProfileString _
          Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
          (ByVal lpApplicationName As String, _
          ByVal lpKeyName As String, ByVal lpString As String, _
          ByVal lpFileName As String) As Integer
        Private Declare Ansi Function GetPrivateProfileInt _
          Lib "kernel32.dll" Alias "GetPrivateProfileIntA" _
          (ByVal lpApplicationName As String, _
          ByVal lpKeyName As String, ByVal nDefault As Integer, _
          ByVal lpFileName As String) As Integer
        Private Declare Ansi Function FlushPrivateProfileString _
          Lib "kernel32.dll" Alias "WritePrivateProfileStringA" _
          (ByVal lpApplicationName As Integer, _
          ByVal lpKeyName As Integer, ByVal lpString As Integer, _
          ByVal lpFileName As String) As Integer

        Dim strFilename As String = ""

        Public Property FileName() As String
            Get
                Return strFilename
            End Get

            Set(Filename As String)
                If File.Exists(Filename) = False Then
                    File.Create(Filename)
                Else
                    strFilename = Filename
                End If
            End Set
        End Property

        Public Function GetString(ByVal Section As String, ByVal Key As String, ByVal [Default] As String) As String
            GetString = ""
            Dim intCharCount As Integer
            Dim objResult As New System.Text.StringBuilder(256)
            intCharCount = GetPrivateProfileString(Section, Key, _
               [Default], objResult, objResult.Capacity, strFilename)
            If intCharCount > 0 Then GetString = Left(objResult.ToString, intCharCount)
        End Function

        Public Function GetInteger(ByVal Section As String, ByVal Key As String, ByVal [Default] As Integer) As Integer
            ' Returns an integer from your INI file
            Return GetPrivateProfileInt(Section, Key, [Default], strFilename)
        End Function

        Public Function GetBoolean(ByVal Section As String, ByVal Key As String, ByVal [Default] As Boolean) As Boolean
            ' Returns a boolean from your INI file
            Return (GetPrivateProfileInt(Section, Key, CInt([Default]), strFilename) = 1)
        End Function

        Public Sub WriteString(ByVal Section As String, ByVal Key As String, ByVal Value As String)
            ' Writes a string to your INI file
            WritePrivateProfileString(Section, Key, Value, strFilename)
            Flush()
        End Sub

        Public Sub WriteInteger(ByVal Section As String, ByVal Key As String, ByVal Value As Integer)
            ' Writes an integer to your INI file
            WriteString(Section, Key, CStr(Value))
            Flush()
        End Sub

        Public Sub WriteBoolean(ByVal Section As String, ByVal Key As String, ByVal Value As Boolean)
            ' Writes a boolean to your INI file
            WriteString(Section, Key, CStr(CInt(Value)))
            Flush()
        End Sub

        Private Sub Flush()
            ' Stores all the cached changes to your INI file
            FlushPrivateProfileString(0, 0, 0, strFilename)
        End Sub

    End Class




End Module
